package cn.cque.service.impl;

import cn.cque.dao.UserDao;
import cn.cque.entity.User;
import cn.cque.service.UserService;
import cn.cque.utils.UUIDUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * Created with IntelliJ IDEA.
 *
 * @author: XWC
 * @ClassName: UserServiceImpl
 * @Date: 2020/10/4
 * @Time: 18:11
 * @Description:
 */
@Service
public class UserServiceImpl implements UserService {

    @Autowired
    UserDao userDao;

    @Override
    public User login(String username, String password) {
        return userDao.findByUsernameAndPassword(username,password);
    }

    @Override
    @Transactional
    public int register(User user) {
        user.setId(UUIDUtils.getId());
        user.setState(0);
        user.setCode(UUIDUtils.getCode());
        int i = userDao.userRegister(user);
        return i;
    }

    @Override
    public List<User> findAll() {
        return userDao.findAll();
    }
}